<script setup lang="ts">

import { ref, onMounted } from 'vue'
import { viewCardAPI } from '@/apis/card'
import type { Card } from '@/types/card';
import { useRoute } from 'vue-router';

const cardInfo = ref<Card>()

const route = useRoute()
const getCardInfo = async() => {
  
  const res = await viewCardAPI(route.params.id as string)
  console.log('res',res)
  cardInfo.value = res.data
}

onMounted(() => {
  getCardInfo()
})

</script>

<template>
  <div class="view-card">
    <header class="view-header">
      <el-page-header content="查看月卡" @back="$router.back()"></el-page-header>
    </header>
    <main class="view-main">
      <div class="form-container">
        <div class="title">车辆信息</div>
        <div class="hang1">
          <div class="item">车主姓名：{{ cardInfo?.personName }}</div> <div class="item">联系方式：{{ cardInfo?.phoneNumber }}</div>
        </div>
        <div class="hang2">
          <div class="item">车牌号码：{{ cardInfo?.carNumber }}</div> <div class="item">车辆品牌：{{ cardInfo?.carBrand }}</div>
        </div>
      </div>

      <div class="table-container">
        <div class="title">月卡缴费记录</div>
        <el-table
          :data="cardInfo?.rechargeList"
          style="width: 100%"
        >
          <el-table-column label="序号"  type="index" width="80"></el-table-column>
          <el-table-column label="有效时间" >
            <template #default="scope">
              {{ scope.row.cardStartDate }} 至 {{ scope.row.cardEndDate }}
            </template>
          </el-table-column>
          <el-table-column prop="paymentAmount" label="支付金额" ></el-table-column>
          <el-table-column prop="paymentMethod" label="支付方式" >
            <template #default="scope">
              {{ scope.row.paymentMethod === 'Alipay' ? '支付宝' : scope.row.paymentMethod === 'WeChat' ? '微信' : '现金' }}
            </template>
          </el-table-column>
          <el-table-column prop="createTime" label="办理时间" ></el-table-column>
          <el-table-column prop="createUser" label="办理人" ></el-table-column>
        </el-table>
      </div>
    </main>
  </div>
</template>

<style scoped lang="scss">
.view-card {
  background: #f4f6f8;
  height: 100vh;
  .view-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;
    background-color: #fff;
  }
  .view-main {
    padding: 20px;
    .form-container {
      margin: 20px 100px;
      padding: 20px;
      background-color: #fff;
      .title {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 20px;
      }
      .hang1 {
        display: flex;
        justify-content: space-around;
        margin-bottom: 20px;
        .item {
          font-size: 14px;
        }
      }
      .hang2 {
        display: flex;
        justify-content: space-around;
        .item {
          font-size: 14px;
        }
      }

    }
    .table-container {
      margin: 20px 100px;
      padding: 20px;
      background-color: #fff;
      .title {
        font-size: 16px;
        font-weight: bold;
        margin-bottom: 20px;
      }
    }
  }
}
</style>